package com.yc.multiple.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration
@EnableTransactionManagement
public class OrderDataSourceConfig {

    @Bean
    @ConfigurationProperties("spring.datasource.order")
    public DataSource orderDataSource(){
        return new HikariDataSource();
    }


    @Bean("orderJdbcTemplate")
    public JdbcTemplate orderJdbcTemplate() throws Exception {

        return new JdbcTemplate(orderDataSource());
    }

    @Bean("dataSourceOrderTransactionManager")
    public DataSourceTransactionManager dataSourceOrderTransactionManager(){
        return new DataSourceTransactionManager(orderDataSource());
    }
}
